/**
 * 
 */
package com.bolbachchan.blog.service.common;

import org.springframework.beans.factory.annotation.Autowired;

import com.bolbachchan.blog.dao.common.UserDetailsDAO;
import com.bolbachchan.blog.hibernate.domain.UserDetails;
import com.googlecode.ehcache.annotations.Cacheable;

/**
 * @author Chaitanya
 * 
 */
public class UserDetailsServiceImpl implements UserDetailsService {

    @Autowired
    private UserDetailsDAO userDetailsDao;

    /*
     * (non-Javadoc)
     * @see com.bolbachchan.blog.service.common.UserDetailsService#
     * getUserDetailsByUsername(com.bolbachchan.blog.dto.LoginDTO)
     */
    @Override
    @Cacheable(cacheName = "userDetails")
    public UserDetails getUserDetailsByUsername(String username) {
	UserDetails userDetails = userDetailsDao.getUserDetailsByUsername(username);

	updateLastLogin(userDetails.getUsername());

	return userDetails;
    }

    /*
     * (non-Javadoc)
     * @see
     * com.bolbachchan.blog.service.common.UserDetailsService#getUserDetailsById
     * (java.lang.Integer)
     */
    @Override
    public UserDetails getUserDetailsById(Integer objId) {
	return userDetailsDao.getUserDetailsById(objId);
    }

    /*
     * (non-Javadoc)
     * @see
     * com.bolbachchan.blog.service.common.UserDetailsService#updateLastLogin
     * (java.lang.String)
     */
    @Override
    public void updateLastLogin(String username) {
	userDetailsDao.updateLastLogin(username);
    }

    /*
     * (non-Javadoc)
     * @see
     * com.bolbachchan.blog.service.common.UserDetailsService#updateLastLogin
     * (java.lang.String)
     */
    @Override
    public void updateLastLogin(UserDetails user) {
	userDetailsDao.updateLastLogin(user);
    }

}
